from pydantic import BaseModel, Field
from datetime import datetime, date
from typing import Optional

class AcademicYearBase(BaseModel):
    year_code: str = Field(..., description="学年编码（如：2025-2026）", max_length=20)
    year_name: str = Field(..., description="学年名称", max_length=50)
    start_date: date = Field(..., description="开始日期")
    end_date: date = Field(..., description="结束日期")
    semester: int = Field(..., description="学期：1-秋季学期 2-春季学期")
    status: int = Field(1, description="状态：0-停用 1-启用")
    is_current: bool = Field(False, description="是否当前学年：0-否 1-是")

class AcademicYearCreate(AcademicYearBase):
    """创建学年学期时使用的模型"""
    pass

class AcademicYearUpdate(BaseModel):
    """更新学年学期时使用的模型"""
    year_code: Optional[str] = None
    year_name: Optional[str] = None
    start_date: Optional[date] = None
    end_date: Optional[date] = None
    semester: Optional[int] = None
    status: Optional[int] = None
    is_current: Optional[bool] = None

class AcademicYear(AcademicYearBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True